package by.msokoloff.javaweb2015.webapp.page.registration;

import javax.inject.Inject;

import org.apache.wicket.extensions.yui.calendar.DateField;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.IModel;

import by.msokoloff.javaweb2015.datamodel.Registration;
import by.msokoloff.javaweb2015.datamodel.TripOrder;
import by.msokoloff.javaweb2015.services.RegistrationService;
import by.msokoloff.javaweb2015.services.TripOrderService;
import by.msokoloff.javaweb2015.webapp.page.EntityListPage;

public class RegistrationForm extends Form<Registration> {

	@Inject
	private RegistrationService registrationService;
	
	@Inject
	private TripOrderService tripOrderService;

	private Registration registration;

	public RegistrationForm(String id, IModel<Registration> model) {
		super(id, model);
		add(new Label("id"));
		add(new DropDownChoice<TripOrder>("tripOrder", tripOrderService.getAll()));
		add(new TextField<String>("firstName"));
		add(new TextField<String>("lastName"));
		add(new TextField<String>("passport"));
		add(new DateField("birthDate"));
				
		add(new FeedbackPanel("feedbackpanel"));
		registration = model.getObject();
	}

	@Override
	public final void onSubmit() {
		registrationService.createOrUpdate(registration);
		setResponsePage(new EntityListPage(Registration.class));
	}

	@Override
	public final void onError() {
		System.out.println("Error!");
	}
}
